package com.cc.mall.web;

import com.cc.common.utils.R;
import com.cc.common.utils.ResponseData;
import com.cc.mall.entity.ProductDetailEntity;
import com.cc.mall.service.ProductService;
import com.cc.mall.vo.ProductDetailVo;
import com.cc.mall.vo.ProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.concurrent.ExecutionException;

@RestController
@RequestMapping("/mall")
@Api(tags = "商城")
public class MallController {

    @Autowired
    private ProductService productService;

    @ApiOperation("通过分类id获取属于该菜单下的所有商品")
    @GetMapping("/getProductListByCatId/{catId}")
    public ResponseData<List<ProductVo>> getProductListByCatId(@ApiParam("商品分类id") @PathVariable("catId") Long catId){
        List<ProductVo> list = productService.getProductListByCatId(catId);
        return ResponseData.success(list);
    }

    @ApiOperation("根据商品id和商品详情id获取数据")
    @GetMapping("/getProductBySkuId")
    public ResponseData<ProductDetailVo> getProductBySkuId(@ApiParam("商品详情id") @RequestParam("skuId") Long skuId,
                               @ApiParam("商品id") @RequestParam("spuId") Long spuId) throws ExecutionException, InterruptedException {
        ProductDetailVo productDetailVo = productService.getProductBySkuId(skuId,spuId);
        return ResponseData.success(productDetailVo);
    }
}
